package com.ruicar.afs.cloud.finance.common.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruicar.afs.cloud.bizcommon.voucher.service.VoucherFlowService;
import com.ruicar.afs.cloud.common.mq.finance.debit.dto.VoucherSuccessDataDto;
import com.ruicar.afs.cloud.finance.common.entity.FinanceBusinessAccounting;
import com.ruicar.afs.cloud.finance.common.mapper.FinanceBusinessAccountingMapper;
import com.ruicar.afs.cloud.finance.common.service.FinanceBusinessAccountingService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>Description: </p>
 *
 * @author ZC.GUO
 * @version 1.0
 * @date create on 2020-07-02 10:18
 */
@Service
@Slf4j
@AllArgsConstructor
public class FinanceBusinessAccountingServiceImpl extends ServiceImpl<FinanceBusinessAccountingMapper, FinanceBusinessAccounting> implements FinanceBusinessAccountingService {
    private final VoucherFlowService voucherFlowService;

    @Transactional(rollbackFor = Exception.class)
    public boolean save(VoucherSuccessDataDto voucherSuccessDataDto) {
     /*   VoucherFlowInfoDto voucherFlowInfoDto = voucherSuccessDataDto.getVoucherFlowInfoDto();
        log.info("合同号：{}，埋点号{}，合同日结-月结===开始保存流水", voucherFlowInfoDto.getBuriedPointNo(), voucherFlowInfoDto.getContractNo());
        voucherSuccessDataDto.getDtos().stream().forEach(financeBusinessAccountingDto -> {
            FinanceBusinessAccounting financeBusinessAccounting = FinanceBusinessAccounting.convertFromInfo(financeBusinessAccountingDto);
            this.save(financeBusinessAccounting);
        });
        IResponse iResponse = voucherFlowService.send(voucherFlowInfoDto);
        if (!CommonConstants.SUCCESS.equals(iResponse.getCode())) {
            log.error("渠道名称：{},凭证流水数据推送失败！", voucherFlowInfoDto.getDealerName());
        }
        Assert.isTrue(CommonConstants.SUCCESS.equals(iResponse.getCode()), "凭证流水数据推送失败！");
        log.info("合同号：{}，埋点号{}，合同日结-月结===结束保存流水", voucherFlowInfoDto.getBuriedPointNo(), voucherFlowInfoDto.getContractNo());*/
        return true;
    }
}